//=========================================================
// cppTutorConcreteObserverDigitalClock.cpp
//
// Implement member functions in DigitalClock class which
// is in file DigitalClock.h
//=========================================================
#include "cppTutorConcreteObserverDigitalClock.h"

DigitalClock::DigitalClock (ClockTimer *s)
{
    _subject = s;
    _subject->Attach(this);
}

DigitalClock::~DigitalClock ()
{
    _subject->Detach(this);
}

// Updates the object's internal state to synchronize with its subject. 
// It uses member functions in the subject object to find out the subject's current state. 
// This Update() function is called by the subject object.    
void DigitalClock::Update (Subject *theChangedSubject)
{
    if(theChangedSubject == _subject)
    {
        Draw();
    }
}

void DigitalClock::Draw ()
{
    int hour = _subject->GetHour();
    int minute = _subject->GetMinute();
    int second = _subject->GetSecond();

    cout << "Digital Clock time is " << hour << ":"
         << minute << ":"
         << second << endl;          
}